﻿using BaseData.API.Read.Applications.Commands;
using BaseData.Domain;
using BaseData.ErrorCode;
using BaseData.Infrastructure.Interfaces;
using MediatR;

namespace BaseData.API.Read.Applications.CommandHandlers
{
    /// <summary>
    /// 绑定功能权限命令
    /// </summary>
    public class BindMenuPerCommandHandler : IRequestHandler<BindMenuPerCommand, ApiResult<List<MenuPermission>>>
    {
        private readonly IBaseRepository<MenuPermission> menuPermissionRep;

        public BindMenuPerCommandHandler(IBaseRepository<MenuPermission> menuPermissionRep)
        {
            this.menuPermissionRep = menuPermissionRep;
        }
        public Task<ApiResult<List<MenuPermission>>> Handle(BindMenuPerCommand request, CancellationToken cancellationToken)
        {
            ApiResult<List<MenuPermission>> result=new ApiResult<List<MenuPermission>>();
            result.Code=ApiEnum.查询成功;
            result.Message=ApiEnum.查询成功.ToString();

            var list = menuPermissionRep.GetAll().ToList();

            result.Data = list;

            return Task.FromResult(result);
        }
    }
}
